package com.rs.game.player.dialogues;

import com.rs.game.player.QuestManager.Quests;

public class Nulodion extends Dialogue {
	
	
	private int npcId;

	@Override
	public void start() {
		npcId = (Integer) parameters[0];
		if (player.getQuestManager().getQuestStage(Quests.DWARF_CANNON) == 9) {
			sendPlayerDialogue(Expressions.NORMAL, "Hello there.");
		} else if (player.getQuestManager().getQuestStage(Quests.DWARF_CANNON) == 10 && !player.getInventory().containsItem(4, 1)) {
			sendPlayerDialogue(Expressions.NORMAL, "Hello again.");
			stage = 7;
		} else if (!player.getInventory().containsItem(4, 1) && player.getQuestManager().completedQuest(Quests.DWARF_CANNON)) {
			sendPlayerDialogue(Expressions.NORMAL, "Hello again.");
			stage = 7;
		} else if (player.getQuestManager().completedQuest(Quests.DWARF_CANNON)) {
			sendPlayerDialogue(Expressions.NORMAL, "Hello again.");
			stage = 10;
		}
	}

	@Override
	public void run(int interfaceId, int componentId) {
		switch (stage) {
		case -1:
			sendNPCDialogue(npcId, Expressions.NORMAL, "Can I help you?");
			stage = 0;
			break;
		case 0:
			sendPlayerDialogue(Expressions.NORMAL, "Captain Lawgof sent me. He's having trouble with his cannon.");
			stage = 1;
			break;
		case 1:
			sendNPCDialogue(npcId, Expressions.NORMAL, "Of course, we forgot to send the ammo mould!");
			stage = 2;
			break;
		case 2:
			sendPlayerDialogue(Expressions.NORMAL, "If fires a mould?");
			stage = 3;
			break;
		case 3:
			sendNPCDialogue(npcId, Expressions.NORMAL, "Don't be silly - the ammo's made by using a mould. Here, take these to him. The instructions explain everything.");
			stage = 4;
			player.getInventory().addItem(3, 1);
			player.getInventory().addItem(4, 1);
			break;
		case 4:
			sendPlayerDialogue(Expressions.NORMAL, "That's great, thanks.");
			stage = 5;
			break;
		case 5:
			sendNPCDialogue(npcId, Expressions.NORMAL, "Thank you, adventurer. The Dwarf Black Guard will remember this.");
			stage = 6;
			break;
		case 6:
			player.getQuestManager().setQuestStageAndRefresh(Quests.DWARF_CANNON, 10);
			player.getPackets().sendGameMessage("The Cannon Engineer gives you some notes and a mould.");
			end();
			break;
		case 7:
			sendPlayerDialogue(Expressions.NORMAL, "I've lost the cannonball mould.");
			stage = 8;
			break;
		case 8:
			sendNPCDialogue(npcId, Expressions.NORMAL, "Deary me, you are trouble. Here, take this one.");
			stage = 9;
			break;
		case 9:
			player.getInventory().addItem(4, 1);
			player.getPackets().sendGameMessage("The Cannon Engineer gives you another mould.");
			end();
			break;
		case 10:
			sendNPCDialogue(npcId, Expressions.NORMAL, "How may I help you?");
			stage = 11;
			break;
		case 11:
			sendOptionsDialogue("Select an Option", "Nothing, thanks.", "I'd like to buy a cannon.");
			stage = 12;
			break;
		case 12:
			switch (componentId) {
			case OPTION_1:
				sendPlayerDialogue(Expressions.NORMAL, "Nothing, thanks.");
				stage = 17;
				break;
			case OPTION_2:
				sendPlayerDialogue(Expressions.NORMAL, "I'd like to buy a cannon.");
				stage = 13;
				break;
			}
			break;
		case 13:
			sendNPCDialogue(npcId, Expressions.NORMAL, "Certainly! That'll be 25,000,000 Coins please.");
			stage = 14;
			break;
		case 14:
			sendOptionsDialogue("Select an Option", "25,000,000 is way too much!", "Okay, here you go.");
			stage = 15;
			break;
		case 15:
			switch (componentId) {
			case OPTION_1:
				sendPlayerDialogue(Expressions.NORMAL, "25,000,000 is way too much!");
				stage = 20;
				break;
			case OPTION_2:
				if (player.getInventory().containsItem(995, 25000000)) {
					sendPlayerDialogue(Expressions.NORMAL, "Okay, here you go.");
					stage = 16;
				} else {
					sendPlayerDialogue(Expressions.SAD, "I don't have that much.");
					stage = 17;
				}
				break;
			}
			break;
		case 16:
			if (player.getInventory().getFreeSlots() >= 4) {
				sendNPCDialogue(npcId, Expressions.NORMAL, "Here you go! Enjoy your new cannon!");
				player.getInventory().deleteItem(995, 25000000);
				player.getInventory().addItem(6, 1);
				player.getInventory().addItem(8, 1);
				player.getInventory().addItem(10, 1);
				player.getInventory().addItem(12, 1);
				stage = 17;
			} else {
				sendNPCDialogue(npcId, Expressions.NORMAL, "You must have at least 4 free slots in your inventory.");
				stage = 17;
			}
			break;
		case 17:
			end();
			break;
		}
	}

	@Override
	public void finish() {
		// TODO Auto-generated method stub
		
	}
}